//
//  JsViewController.m
//  JsUtilitySdk
//
//  Created by Gikki Ares on 2023/5/22.
//

/**
 1,vc的vm不主动创建了,有就使用,没有也能用.
 */

#import "JsViewController.h"

@implementation JsViewControllerVm


@end

@interface JsViewController (){
	int mi_updateCount;
}

@end

@implementation JsViewController

/**
 1,init的时候创建默认vm.
 2,
 */
- (instancetype)init {
	if(self = [super init]) {
		_vm = [JsViewControllerVm new];
	}
	return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
	[self updateVm];
}


- (void)setVm:(JsViewControllerVm *)vm {
	_vm = vm;
	[self updateVm];
}

- (void)renderVm {
	self.view.backgroundColor = _vm.backgroundColor;
	self.navigationItem.titleView.tintColor = [UIColor blackColor];
}

-(void)updateVm {
	mi_updateCount ++;
	if(mi_updateCount == 1) {
		dispatch_async(dispatch_get_main_queue(), ^{
			if(self->_vm) {
				[self renderVm];
			}
			self->mi_updateCount=0;
		});
	}
}
@end
